package pa14.asmt.a2.test;

public class Car {
	private String ownerName;
	private int numWheels;
	private static int numInstances = 0;
	public static final String clName = "CarClass";

	public String getclassname(){
		return clName;
	}
	
	public int getNumWheels(){
		return numWheels;
	}
	
	public String getOwnerName(){
		return "The owner is: " + ownerName;
	}
	
	public Car(){
		this.ownerName = "Unknown";
		this.numWheels = 2;
		numInstances++;
	}
	
	public Car(String owner){
		this.ownerName = owner;
		this.numWheels = 2;
		numInstances++;
	}
	
	public static int getNumInstances() throws Exception{
		if(numInstances < 5){
			return numInstances;
		}else{
			throw new Exception("Too many instances of this class");
		}
	}
	
	public static void main(String[] args) {
		Car c = new Car();
		Car d = new Car("Shivam");
		
		System.out.println(c.getNumWheels());
		System.out.println(d.getOwnerName());
		
		try{
			System.out.println("The total number of instances are:" + Car.getNumInstances());
		}catch(Exception e){
			e.printStackTrace();
		}
		
		c = null;
		d = null;
	}

}
